<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- 引入 Font Awesome 图标 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css">
    <title>天气⻛数据查询</title>
    <style>
        /* 全局样式重置 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        /* 基础样式 */
        body {
            font-family: "Microsoft YaHei", Arial, sans-serif;
            background-color: #f5f5f5;
            color: #333;
            line-height: 1.6;
        }

        .container {
            width: 90%;
            max-width: 1200px;
            margin: 20px auto;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
            padding: 20px;
        }

        h1 {
            text-align: center;
            color: white;
            background-color: #2c3e50;
            padding: 15px 0;
            border-radius: 5px;
            margin-bottom: 20px;
        }

        /* 表单样式 */
        form {
            display: flex;
            flex-wrap: wrap;
            gap: 15px;
            padding: 15px;
            background-color: #f9f9f9;
            border-radius: 5px;
            margin-bottom: 20px;
        }

        .form-group {
            flex: 1;
            min-width: 200px;
        }

        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: #555;
        }

        select, button {
            padding: 10px 15px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
        }

        select {
            width: 100%;
            appearance: none;
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8.5L2.5 5l3.5-3.5L10 5z'/%3E%3C/svg%3E");
            background-repeat: no-repeat;
            background-position: right 10px center;
            background-size: 12px;
        }

        button {
            background-color: #2ecc71;
            color: white;
            border: none;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        button:hover {
            background-color: #27ae60;
        }

        /* 数据展示区 */
        .filter-info {
            display: flex;
            justify-content: space-between;
            align-items: center;
            background-color: #f0f0f0;
            padding: 12px 15px;
            border-radius: 5px;
            margin: 15px 0;
            flex-wrap: wrap;
            gap: 10px;
        }

        .summary {
            background-color: #2ecc71;
            color: white;
            padding: 6px 12px;
            border-radius: 4px;
            font-size: 14px;
        }

        .reset-button {
            background-color: #3498db;
            color: white;
            text-decoration: none;
            padding: 8px 16px;
            border-radius: 4px;
            display: inline-block;
            transition: background-color 0.3s;
            align-items: center;
            justify-content: center;
        }

        .reset-button i {
            margin-right: 5px;
        }

        .reset-button:hover {
            background-color: #2980b9;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
        }

        th, td {
            padding: 12px 15px;
            border: 1px solid #eee;
            text-align: left;
        }

        th {
            background-color: #2c3e50;
            color: white;
            position: sticky;
            top: 0;
            z-index: 10;
        }

        tr:nth-child(even) {
            background-color: #f9f9f9;
        }

        tr:hover {
            background-color: #f0f8ff;
        }

        .no-data {
            text-align: center;
            padding: 40px 0;
            color: #777;
            font-size: 16px;
        }

        .no-data i {
            color: #3498db;
            margin-right: 10px;
            font-size: 24px;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            form {
                flex-direction: column;
            }

            .form-group {
                min-width: 100%;
            }

            table {
                display: block;
                overflow-x: auto;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>天气数据查询系统</h1>

        <!-- 查询表单 -->
        <form action="/weather/query" method="GET">
            <div class="form-group">
                <label for="urban">城市选择</label>
                <select name="urban" id="urban">
                    <option value="" {% if not urban %}selected{% endif %}>请选择城市</option>
                    {% for city in cities %}
                        <!-- 默认选中上海 -->
                        <option value="{{ city }}" {% if city == urban or (not urban and city == '上海') %}selected{% endif %}>
                            {{ city }}
                        </option>
                    {% endfor %}
                </select>
            </div>

            <div class="form-group">
                <label for="goods">空气质量等级</label>
                <select name="goods" id="goods">
                    <option value="" {% if not goods_choice %}selected{% endif %}>请选择等级</option>
                    {% for grade in goods %}
                        <!-- 默认选中良 -->
                        <option value="{{ grade }}" {% if grade == goods_choice or (not goods_choice and grade == '良') %}selected{% endif %}>
                            {{ grade }}
                        </option>
                    {% endfor %}
                </select>
            </div>

            <button type="submit"><i class="fa fa-search"></i> 查询数据</button>
        </form>

        <!-- 筛选信息展示 -->
        <div class="filter-info">
            <span>当前筛选：城市 - {{ urban | default('未选择', true) }}，空气质量等级 - {{ goods_choice | default('未选择', true) }}</span>

            {% if total_count is defined %}
                <div class="summary">
                    <i class="fa fa-list"></i> 记录总数：{{ total_count }}
                </div>
            {% endif %}
        </div>

        <!-- 数据表格或无数据提示 -->
        {% if data and data.date and data.date|length > 0 %}
            <table>
                <thead>
                    <tr>
                        <th>序号</th>
                        <th>空气质量等级</th>
                        <th>最低温度 (°C)</th>
                        <th>日期</th>
                        <th>最高温度 (°C)</th>
                        <th>空气质量指数</th>
                    </tr>
                </thead>
                <tbody>
                    {% for i in range(data.date|length) %}
                        <tr>
                            <td>{{ i + 1 }}</td>
                            <td>{{ data.aqi_level[i] }}</td>
                            <td>{{ data.low_temperature[i] }}</td>
                            <td>{{ data.date[i] }}</td>
                            <td>{{ data.high_temperature[i] }}</td>
                            <td>{{ data.air_quality_index[i] }}</td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        {% else %}
            <div class="no-data">
                <i class="fa fa-info-circle"></i>
                <p>没有查询到符合条件的天气数据，请调整筛选条件后重试</p>
            </div>
        {% endif %}
    </div>
</body>
</html>